<?php

namespace App\Notifications;

use App\Channel\WechatChannel;
use App\Channel\WorkMiniCard;
use App\model\customer\Customer;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class WechatNotification extends Notification implements  ShouldQueue
{
    use Queueable;
    protected  $customer;
    protected $title;
    protected $desc;
    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Customer $customer,$title='',$desc='')
    {

        $this->customer=$customer;
        $this->title=$title;
        $this->desc=$desc;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [WechatChannel::class];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }
    public function toWechat(){
        if ($this->title){
            return new WorkMiniCard([
                'appid'=>'wxa3225a06c201240e',
                'page'=>'packageA/pages/allotWrap/detail/detail?customer_id='.$this->customer->customer_id,
                'title'=>$this->title,
                'description'=>$this->desc
            ]);
        }
        if ($this->customer->status==Customer::FOLLOW_TO_GROUP){
          $message=  new WorkMiniCard([
                'appid'=>'wxa3225a06c201240e',
              'page'=>'packageA/pages/allotWrap/detail/detail?customer_id='.$this->customer->customer_id,
              'title'=>'客户名称:'.$this->customer->name,
                'description'=>'客户已创建，请前往分配'
            ]);
        }

        if ($this->customer->status==Customer::FOLLOW_TO_USER){
            $message=  new WorkMiniCard([
                'appid'=>'wxa3225a06c201240e',

                'page'=>'packageA/pages/allotWrap/detail/detail?customer_id='.$this->customer->customer_id,
                'title'=>'有客到:'.$this->customer->name,
                'description'=>'同事们，快出来接客啦！'
            ]);
        }
        if ($this->customer->status==Customer::NO_FOLLOW){
            $message=  new WorkMiniCard([
                'appid'=>'wxa3225a06c201240e',
                'page'=>'packageA/pages/allotWrap/detail/detail?customer_id='.$this->customer->customer_id,
                'title'=>'客户名称:'.$this->customer->name,
                'description'=>'客户已创建，请前往分配'
            ]);
        }
        return $message;
    }
    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}
